function debounce(f, wait) {
    let timer
    return (...args) => {
        clearTimeout(timer)
        timer = setTimeout(() => {
            f(...args)
        }, wait)
    }
}

function throttle(f, wait) {
    let timer
    return (...args) => {
        if (timer) { return }
        timer = setTimeout(() => {
            f(...args)
            timer = null
        }, wait)
    }
}

var dd = debounce((a)=>{
    console.log(a)
}, 500)

let n  = 0
const timer = setInterval(()=>{
    dd('args')
    n++
    if(n > 10){
        clearInterval(timer)
    }
}, 300)